import React from 'react'
import { Redirect } from 'react-router-dom'
import * as routerTypes from '@/constants/routerType'

import Login from '@/pages/blog/login'
import VerifyLogin from '@/pages/blog/verifyLogin'
import Error from '@/components/b_error'

const localUser = JSON.parse(localStorage.getItem('user')) || {}

const routes = [
  {
    path: '/',
    exact: true,
    render: () => {
      return localUser.id ? (
        <Redirect to={`/blog/home/u/${localUser.id}`} />
      ) : (
        <Redirect to={`/login`} />
      )
    }
  },
  {
    path: '/blog/home/u/:id',
    type: routerTypes.HOME,
    component: VerifyLogin
  },
  {
    path: '/blog/archives/u/:id',
    type: routerTypes.ARCHIVES,
    component: VerifyLogin
  },
  {
    path: '/blog/friends/u/:id',
    type: routerTypes.FRIENDS,
    component: VerifyLogin
  },
  {
    path: '/blog/wall/u/:id',
    type: routerTypes.WALLS,
    component: VerifyLogin
  },
  {
    path: '/blog/profile/u/:id',
    type: routerTypes.PROFILE,
    component: VerifyLogin
  },
  {
    path: '/blog/detail',
    type: routerTypes.DETAIL,
    component: VerifyLogin
  },
  {
    path: '/blog/category/u/:id/:classifyId',
    type: routerTypes.CATEGORY,
    component: VerifyLogin
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '*',
    component: Error
  }
]

export default routes
